<template>
  <div>
    <el-row>
      <el-col :span="22">
        <p class="pinformation" style="margin-top: 7px">基本信息</p>
      </el-col>
      <el-col :span="2">
        <el-button link type="success">导出方案单</el-button>
      </el-col>
    </el-row>
    <el-form label-width="100px" :model="form">
      <el-row>
        <el-col :span="6">
          <el-form-item label="方案编号：">
            {{ form.projectCode || "/" }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="方案名称：">
            {{ form.projectName || "/" }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="方案类型：">
            <dict-tag :options="sys_contract_type" :value="form.contractType" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="方案执行时间：">
            {{ form.planDate }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="采样员：">
            {{ form.cyUserName }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="紧急类型：">
            <dict-tag :options="sys_degree" :value="form.degree" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="委托单位名称：">
            {{ form.wtCustomName }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="委托单位地址：">
            {{ form.wtAddress }}
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="联系人：">
            {{ form.wtContacts }}
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="联系电话：">
            {{ form.wtPhonenumber }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="受检单位名称：">
            {{ form.sjCustomName }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="受检单位地址：">
            {{ form.sjAddress }}
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="联系人：">
            {{ form.sjContacts }}
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="联系电话：">
            {{ form.sjPhonenumber }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-form :model="queryParams" ref="queryRef">
      <el-row>
        <el-col :span="1.5">
          <p class="pinformation" style="margin-top: 10px">检测内容列表</p>
        </el-col>
        <el-col :span="2">
          <p class="totalStyle" style="margin-top: 7px">
            共 {{ total }} 条数据
          </p>
        </el-col>
        <el-col :span="3">
          <el-form-item label="检测类别：" prop="jclbId">
            <el-select v-model="queryParams.jclbId" clearable style="width: 100%">
              <el-option v-for="item in proxy.addListNoLimit(
                jclbList,
                'jclbId',
                'jclbName'
              )" :key="item.jclbId" :value="item.jclbId" :label="item.jclbName" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="检测项目：" prop="jcxmName">
            <el-input v-model="queryParams.jcxmName" clearable maxlength="100" @keyup.enter="handleQuery"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="方法编号：" prop="methodCode">
            <el-input v-model="queryParams.methodCode" clearable maxlength="100" @keyup.enter="handleQuery"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="点位名称：" prop="pointName">
            <el-input v-model="queryParams.pointName" clearable maxlength="100" @keyup.enter="handleQuery"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="是否分包：" prop="isPackage">
            <el-col :span="5"><el-tooltip class="box-item" effect="customized" content="意为该方案中的某些检测项目为分包项目，但需己方采样。"
                placement="bottom">
                <svg-icon :icon-class="'wenhao'" class="mark" /> </el-tooltip></el-col>
            <el-col :span="19">
              <el-select clearable v-model="queryParams.isPackage">
                <el-option v-for="dict in isPackageList" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)" />
              </el-select>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-row justify="end">
            <el-button type="success" @click="handleQuery">搜索</el-button>
            <el-button class="business resetBtn" @click="resetQuery">重置</el-button>
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <el-table ref="mainTableRef" :data="projectList">
      <el-table-column prop="methodJcxm.jclbName" label="检测类别" align="center" show-overflow-tooltip>
        <template #default="scope">
          {{ scope.row.projectPoint.jclbName }}
        </template>
      </el-table-column>
      <el-table-column prop="projectPoint.pointName" label="点位名称" align="center" show-overflow-tooltip />
      <el-table-column prop="projectPoint.pointCode" label="点位编号" align="center" show-overflow-tooltip />
      <el-table-column prop="jcxmName" label="检测项目" align="center" width="110" show-overflow-tooltip>
        <template #default="scope">
          <span v-html="transformation(scope.row.jcxmName)"></span>
        </template>
      </el-table-column>
      <el-table-column prop="sampleDay" label="连测天数" align="center" width="80" show-overflow-tooltip />
      <el-table-column prop="sampleCount" label="每天频次" align="center" width="80" show-overflow-tooltip />
      <el-table-column prop="methodJcxm.methodCode" label="方法编号" align="center" width="130" show-overflow-tooltip />
      <el-table-column prop="methodJcxm.methodName" label="方法名称" align="center" width="300" show-overflow-tooltip />
      <el-table-column prop="" label="特别说明" align="center" show-overflow-tooltip />
      <el-table-column label="是否分包" align="center" width="80" show-overflow-tooltip>
        <template #default="scope">
          {{
            scope.row.isPackage == 0 ? "否" : "是"
          }}
        </template>
      </el-table-column>
      <el-table-column prop="packageName" label="分包公司" align="center" width="300" show-overflow-tooltip />
      <el-table-column prop="pjUpLimit" label="评价下线" align="center" width="80" show-overflow-tooltip />
      <el-table-column prop="pjDownLimit" label="评价上线" align="center" width="80" show-overflow-tooltip />
      <el-table-column prop="pjUnit" label="评价单位" align="center" width="80" show-overflow-tooltip />
      <el-table-column prop="" label="评价标准" align="center" width="80" show-overflow-tooltip />
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script setup>
import { getCyJcxmList, getProjectCy } from "@/api/cyCheck/cyReady";
import { projectListJclb } from "@/api/store/jclb";
const { proxy } = getCurrentInstance();
const {
  sys_contract_type,
} = proxy.useOrgDict(
  "sys_contract_type",
);
const { sys_degree } = proxy.useDict("sys_degree");
const queryParams = ref({
  pageSize: 10,
  pageNum: 1,
  jclbId: -1,
  isPackage: -1
});
const form = ref({ contract: {} });
const isPackageList = ref([
  { value: -1, label: "不限" },
  { value: 0, label: "否" },
  { value: 1, label: "是" },
]);
const dateRange = ref([]);
const total = ref(0);
const projectList = ref([]);
const jclbList = ref([]);
const cyUserList = ref([]);

const props = defineProps({
  projectId: {
    type: String, //参数类型
  },
});

// getDialogUserList().then((res) => {
//   cyUserList.value = res.data;
// });

function getId() {
  nextTick(() => {
    queryParams.value.projectId = props.projectId;
    getProjectCy(queryParams.value.projectId).then((res) => {
      form.value = res.data;
    });
    getList();
  });
}

function getList() {
  getCyJcxmList(queryParams.value).then((res) => {
    projectList.value = res.rows;
    total.value = res.total;
  });
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

getId();

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "main", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "main", bottomHeight: 22 }];
    }
    getTableHeight();
  }
);

const heightParams = ref([{ tableName: "main", bottomHeight: 73 }]);

function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
})

onUpdated(() => {
  nextTick(function () {
    getTableHeight();
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

function transformation(row) {
  const a = proxy.getSupAndSub(row);
  return a;
}

projectListJclb({ projectId: props.projectId }).then((res) => {
  jclbList.value = res.data;
});

// 记得暴露
defineExpose({
  getList,
});
</script>

<style></style>
